﻿using GamFi.API.Application.Contracts.Chat.GetMessages;
using GamFi.API.Application.Features.Queries.Chat.GetMessages;
using MediatR;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;

namespace GamFi.API.WEB.Controllers;

[Authorize]
[ApiController]
[Route("api/[controller]")]
public class ChatController: ControllerBase
{
    private readonly IMediator _mediator;

    /// <summary>
    /// Конструктор
    /// </summary>
    /// <param name="mediator">Медиатор из библиотеки MediatR</param>
    public ChatController(IMediator mediator) => _mediator = mediator;
    
    /// <summary>
    /// Возвращаю все сообщения
    /// </summary>
    /// <param name="cancellationToken"></param>
    /// <returns></returns>
    [HttpGet("GetMessages")]
    public async Task<GetMessagesResponse> GetMessages(CancellationToken cancellationToken)
    => await _mediator.Send(new GetMessagesQuery(), cancellationToken);
}